<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList"
		:loading-more-custom-style="{ paddingBottom: 'env(safe-area-inset-bottom)' }">
		<template #top>
			<view class="zpagin_top">
				<nav-bar :iconLeft="true" />
				<view class="search">
					<custom-search v-model="queryParams.search" @search="refreshList" placeholder="请输入物品名称/物品编号" />
					<uni-data-select style="z-index: 50;" placeholder="请选择仓库" v-model="queryParams.warehouse__id"
						:localdata="warehouse_list" @change="refreshList" />
				</view>
				<dui-float-ball :pathUrl="`${pageUrl}/compile`" v-if="$hasPerm(['80101'])" />
			</view>
		</template>
		<uni-card v-for="item in dataList" :key="item.id" margin="5px" spacing="0" :title="item.s_name"
			:sub-title="item.s_code" @click="goDetail(item, pageUrl, '80102')">
			<view class="text-2">仓库名称：{{ item.warehouse_name }}</view>
			<view class="text-2">规格：{{ item.s_specification }}</view>
			<view class="text-2">库存：{{ item.unit_info }}</view>
			<view class="text-2">变动时间：{{ item.change_date }}</view>
		</uni-card>

	</z-paging>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import wareInventoryApi from '../../../api/warehouse/ware_inventory'
import { goDetail } from '@/utils/permission'

uni.$bus.useBusOn('w_inventory:refresh', refreshList)


onLoad(option => {
	
	get_warehouse_list()
})

const pageUrl = '/views/warehouse/w_inventory'

//数据请求
const paging = ref(null);
const dataList = ref([]);
const queryParams = reactive({
})
function queryList(pageNo, pageSize) {
	const params = {
		page: pageNo,
		page_size: pageSize,
		...queryParams
	}
	wareInventoryApi.get_stock_control(params).then((res) => {
		paging.value.complete(res.results);
	})
}

const warehouse_list = ref([])
function get_warehouse_list() {
	const params = { page: 1, page_size: 99999, if_open: 1 };
	wareInventoryApi.get_warehouse(params).then(res => {
		warehouse_list.value = res.results.map(v => ({
			text: v.name,
			value: v.id
		}))
	})
}

//编辑跳转刷新
function refreshList() {
	paging.value.reload();
}

</script>

<style lang="scss"></style>